package br.com.rise.leilao.financeiro

import grails.test.*
import br.com.rise.leilao.Endereco

class AgenciaTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }
	
	//testando se passa
	void testConstraintsSucesso() {
		
		mockDomain Agencia, []
		def e = new Endereco()
		def b = new Banco()
		def ag = new Agencia(numero: "001", endereco: e, banco: b)
		assertTrue ag.validate()
	}
	
	//testando a constraint nullable do codigo
	void testNumeroConstraintsNullable() {
		
		mockDomain Agencia, []
		def e = new Endereco()
		def b = new Banco()
		def ag = new Agencia(endereco: e, banco: b)
		assertFalse ag.validate()
		assertEquals "nullable", ag.errors['numero']
	}
	
	//testando a constraint blank do campo nome
	void testNumeroConstraintsBlank() {

		mockDomain Agencia, []
		def e = new Endereco()
		def b = new Banco()
		def ag = new Agencia(numero: "", endereco: e, banco: b)
		assertFalse ag.validate()
		assertEquals "blank", ag.errors['numero']
	}
	
	//testando a constraint nullable do codigo
	void testEnderecoConstraintsNullable() {
		
		mockDomain Agencia, []
		def b = new Banco()
		def ag = new Agencia(numero: "001", banco: b)
		assertFalse ag.validate()
		assertEquals "nullable", ag.errors['endereco']
	}
	
	//testando a constraint nullable do codigo
	void testBancoConstraintsNullable() {
		
		mockDomain Agencia, []
		def e = new Endereco()
		def ag = new Agencia(numero: "001", endereco: e)
		assertFalse ag.validate()
		assertEquals "nullable", ag.errors['banco']
	}
	

}
